import React, { Component } from 'react';
import store from '../../store2';
// 导入actions 所有的任务(包括同步任务和异步任务)
import {
    addcountaction,
    addcountactioAsync,
    addmoneyaction,
    getschoollist
} from '../../store2/actions/action'
class Mycls extends Component {
    constructor() {
        super()
        // 初始化赋值
        this.state = store.getState()
        console.log('state', this.state);

        store.subscribe(() => this.setState(() => store.getState()))
    }
    render() {
        return (
            <div>
                <p>count: {this.state.reducer.count}</p>
                <p><button onClick={this.addCount}>count+10 同步</button></p>
                <p><button onClick={this.addCountAsycn}>count+10 异步</button></p>
                <p>money:{this.state.reducer1.money}</p>
                <p><button onClick={this.addMoney}>moeny++</button></p>
                <hr />
                {/*  展示院校数据 */}
                <ul>
                    {this.state.reducer2.schoolArr.map((item) => {
                        return <li key={item.id}>{item.school_name}</li>
                    })}
                </ul>
            </div>
        );
    };
    // 同步修改
    addCount = () => {
        // 在页面中点击+,2秒后 实现count+1
        // setTimeout(() => {
        // store.dispatch({ type: '+', payload: 1 })
        // }, 2000)
        // 同步修改state
        store.dispatch(addcountaction(10))
    };
    // 异步修改
    addCountAsycn() {
        store.dispatch(addcountactioAsync(10))
    }

    addMoney = () => {
        store.dispatch(addmoneyaction())
    };
    componentDidMount() {
        // 页面初始化进行数据请求
        // store.dispatch(getschoollist())

    }
}

export default Mycls;
